<template>
  <div class="football">
    <van-nav-bar left-arrow="true" @click-left="onClickLeft" @click-right="onClickRight">
      <span slot="title" v-text="titleName"></span>
      <span slot="right">
        <span class="iconfont icon-funnel"></span>
        <i class="iconfont icon-more"></i>
      </span>
    </van-nav-bar>

    <van-collapse v-model="activeName">
      <van-collapse-item
        :title="(index==='is_hot'?'热门':(item[0].changciWeek+' '+index))+' 共'+item.length+'场比赛可投注'"
        :name="index"
        v-for="(item ,index) in listDate"
        :key="index"
      >
        {{item.is_hot}}
        <comList :is_type="7" :listItem="item"></comList>
      </van-collapse-item>
    </van-collapse>
    <div v-if="showTips" class="footBall_buttom_tips">页面赔率仅供参考，请以出票为准</div>
    <!-- 更多选项 -->
    <van-popup v-model="moreControl" class="moreControl">
      <ul>
        <li>购彩记录</li>
        <li>开奖信息</li>
        <li>玩法介绍</li>
      </ul>
    </van-popup>
    <!-- 赛事类型筛选 -->
    <van-popup v-model="eventTypeSelect" class="event_type_select">
      <h3>赛事筛选</h3>
      <van-row class="event_type_select_control">
        <van-col span="8">全选</van-col>
        <van-col span="8">反选</van-col>
        <van-col span="8">仅5大联赛</van-col>
      </van-row>
      <ul class="btn_ul">
        <li v-for="(tval,tkey) of matchName" :key="tkey" v-text="tkey" class="is_choosed"></li>
      </ul>
      <div class="botton_btn">
        <van-button type="default" class="button_esc">取消</van-button>
        <van-button type="primary" class="button_isok">确认</van-button>
      </div>
    </van-popup>
    <div v-if="isLoading" class="XC_loading">
      <van-loading color="#333"/>
    </div>
  </div>
</template>
<script>
import comList from "./components/football_com_list.vue";
import {
  Button,
  Row,
  Col,
  Collapse,
  CollapseItem,
  Loading,
  NavBar,
  Popup
} from "vant";


export default {
  name: "xc-header",
  components: {
    NavBar,
    comList,
    Collapse,
    CollapseItem,
    Loading,
    Popup,
    Row,
    Col
  },
  data() {
    return {
      listDate: [],
      showTips: true,
      activeName: [],
      isLoading: false,
      titleName: "竞彩足球-混合过关",
      moreControl: false,
      matchName: {}, // 赛事列表
      eventTypeSelect: false
    };
  },
  props: {},
  watch: {},
  methods: {
    // 头部跳转
    onClickLeft() {
      this.$router.push({
        path: "/index"
      });
    },
    // 点击右边的事件
    onClickRight(obj) {
      if (obj.target.nodeName === "SPAN") {
        console.log("过滤");
        this.eventTypeSelect = true;
      } else if (obj.target.nodeName === "I") {
        console.log("更多");
        this.moreControl = true;
      }
    },
    transformData(obj) {
      if (obj) {
        let tempDateTime = null;
      } else {
        return {};
      }
    },
    initData() {
      this.isLoading = true;
      this.$api.getJczqMatch({}).then(
        res => {
          if (res.http_code === 200) {
            let DataArray = {};
            let tempDateTime = null;
            this.showTips = res.data.length;
            for (let item of res.data) {
              // 时间处理(投注时间为结束时间前五分钟)
              tempDateTime = new Date((item.match_time_int - 300) * 1000);
              item.overDateTime =
                tempDateTime.getHours() + ":" + tempDateTime.getMinutes();
              // 赛事文件名称
              this.matchName[item.match_name] = 1;

              // 处理热门
              if (item.is_hot === "1") {
                item.changciWeek = item.changci.substring(0, 2);
                item.Num = item.match_id.substring(8);
                if (DataArray["is_hot"] == undefined) {
                  DataArray["is_hot"] = [item];
                } else {
                  DataArray["is_hot"].push(item);
                }
              } else {
                // 处理标题
                item.changciWeek = item.changci.substring(0, 2);
                item.Num = item.match_id.substring(8);
                if (DataArray[item.number_date] == undefined) {
                  DataArray[item.number_date] = [item];
                } else {
                  DataArray[item.number_date].push(item);
                }
              }
            }
            console.log(this.matchName);
            this.$nextTick(function() {
              console.log(DataArray);
              // this.listDate = DataArray;
              // this.activeName = [res.data[0].number_date];
              // 首先渲染第一个手风琴，将数据呈现出来，然后在渲染后续的数据
              if (DataArray["is_hot"] === undefined) {
                this.listDate = [DataArray[res.data[0].number_date]];
                this.activeName = [res.data[0].number_date];
              } else {
                this.listDate = [DataArray["is_hot"]];
                this.activeName = ["is_hot"];
              }

              let _this = this;
              setTimeout(function() {
                _this.listDate = DataArray;
              }, 1);
            });
          }
          this.isLoading = false;
        },
        error => {
          this.isLoading = false;
        }
      );
    }
  },
  activated() {
    this.initData();
  },
  created() {}
};
</script>
<style lang="less" scoped>
@import url(../../style/temp.less);

.football {
  // 赛事选择
  .event_type_select {
    width: 90%;
    height: 370px;
    border-radius: 4px;
    h3 {
      position: relative;
      height: 40px;
      line-height: 40px;
      font-size: 16px;
      font-weight: 400;
      text-align: center;
      ::before {
        position: absolute;
        top: 50%;
        width: 1.4rem;
        height: 1px;
        background-color: hsla(0, 0%, 91%, 0.8);
        content: "";
      }
      ::after {
        position: absolute;
        top: 50%;
        width: 1.4rem;
        height: 1px;
        background-color: hsla(0, 0%, 91%, 0.8);
        content: "";
      }
    }
    .event_type_select_control {
      margin: 10px 15px;
      height: 35px;
      line-height: 35px;
      text-align: center;
      font-size: 15px;
      border: 1px solid #e8e8e8cc;
      .van-col {
        &:nth-child(2) {
          border-left: 1px solid #e8e8e8cc;
          border-right: 1px solid #e8e8e8cc;
        }
      }
    }
    .botton_btn {
      padding: 10px 15px;
      .van-button {
        width: 150px;
        font-size: 15px;
        height: 45px;
        line-height: 45px;
        text-align: center;
        border-radius: 25px;
      }
      .button_esc {
        background-color: #fff;
        border: 1px solid #ff473a;
        color: #ff473a;
      }
      .button_isok {
        border: 1px solid #ff473a;
        background-color: #ff473a;
        color: #fff;
      }
    }
  }
  .btn_ul {
    padding: 15px;
    font-size: 0;
    max-height: 185px;
    overflow: auto;
    .is_choosed {
      border-color: #ff473a;
      color: #ff473a;
    }
    li {
      display: inline-block;
      font-size: 15px;
      margin-left: 15px;
      border: 1px solid hsla(0, 0%, 91%, 0.8);
      width: 90px;
      height: 35px;
      line-height: 35px;
      text-align: center;
      margin-bottom: 10px;
      border-radius: 5px;
      overflow: hidden;
      &:nth-child(3n + 1) {
        margin-left: 0;
      }
    }
  }
}
.football .icon-funnel {
  position: relative;
  left: -15px;
}

.van-collapse-item__content {
  padding: 0;
}
.van-collapse-item__wrapper,
.van-collapse-item__content {
  color: @primary-color;
  background-color: @default-background-color;
}
.footBall_buttom_tips {
  margin-top: 10px;
  text-align: center;
  font-size: 14px;
  color: @theme-color;
}
.moreControl {
  top: 14%;
  left: none;
  right: -160px;
  background-color: transparent;

  ul {
    width: 6rem;
    background-color: #fff;
    float: right;
    margin-top: 50px;

    li {
      height: 45px;
      line-height: 45px;
      border-bottom: 1px solid #eee;
      text-align: center;
      font-size: 16px;

      &:last-child {
        border-bottom: none;
      }
    }
  }
}
.XC_loading {
  position: fixed;
  top: 50%;
  left: 50%;
  display: inline-block;

  width: 30px;
  height: 30px;
  padding: 25px;
  border-radius: 4px;
  z-index: 9999;
  line-height: 0;
  vertical-align: middle;
  background-color: rgba(0, 0, 0, 0.5);

  overflow: hidden;
  -webkit-transition: 0.3s;
  transition: 0.3s;
  -webkit-transform: translate3d(-50%, -50%, 0);
  transform: translate3d(-50%, -50%, 0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
</style>
